/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package by.bsuir.bbs.persistence;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Администратор
 */
@Entity
@Table(name = "comment")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Comment.findAll", query = "SELECT c FROM Comment c"),
    @NamedQuery(name = "Comment.findByCommentId", query = "SELECT c FROM Comment c WHERE c.commentPK.commentId = :commentId"),
    @NamedQuery(name = "Comment.findByCreationTime", query = "SELECT c FROM Comment c WHERE c.creationTime = :creationTime"),
    @NamedQuery(name = "Comment.findByLike", query = "SELECT c FROM Comment c WHERE c.like = :like"),
    @NamedQuery(name = "Comment.findByAdIdAd", query = "SELECT c FROM Comment c WHERE c.commentPK.adIdAd = :adIdAd"),
    @NamedQuery(name = "Comment.findByAdUserIduser", query = "SELECT c FROM Comment c WHERE c.commentPK.adUserIduser = :adUserIduser")})
public class Comment implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CommentPK commentPK;
    @Lob
    @Column(name = "message")
    private byte[] message;
    @Column(name = "creation_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date creationTime;
    @Column(name = "like")
    private Integer like;
    @JoinColumns({
        @JoinColumn(name = "ad_id_ad", referencedColumnName = "ad_id", insertable = false, updatable = false),
        @JoinColumn(name = "ad_user_iduser", referencedColumnName = "user_iduser", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Ad ad;

    public Comment() {
    }

    public Comment(CommentPK commentPK) {
        this.commentPK = commentPK;
    }

    public Comment(int commentId, int adIdAd, int adUserIduser) {
        this.commentPK = new CommentPK(commentId, adIdAd, adUserIduser);
    }

    public CommentPK getCommentPK() {
        return commentPK;
    }

    public void setCommentPK(CommentPK commentPK) {
        this.commentPK = commentPK;
    }

    public byte[] getMessage() {
        return message;
    }

    public void setMessage(byte[] message) {
        this.message = message;
    }

    public Date getCreationTime() {
        return creationTime;
    }

    public void setCreationTime(Date creationTime) {
        this.creationTime = creationTime;
    }

    public Integer getLike() {
        return like;
    }

    public void setLike(Integer like) {
        this.like = like;
    }

    public Ad getAd() {
        return ad;
    }

    public void setAd(Ad ad) {
        this.ad = ad;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (commentPK != null ? commentPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Comment)) {
            return false;
        }
        Comment other = (Comment) object;
        if ((this.commentPK == null && other.commentPK != null) || (this.commentPK != null && !this.commentPK.equals(other.commentPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "by.bsuir.bbs.jpa.Comment[ commentPK=" + commentPK + " ]";
    }
    
}
